package io.yx.flx.handler;

import cn.hutool.core.date.DateUtil;
import cn.hutool.db.Db;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

import java.sql.SQLException;

/**
 * @author YX
 * @date 2022/11/18 10:11
 */
public class TodayFileTotalHandler implements Handler<RoutingContext> {
    @Override
    public void handle(RoutingContext rc) {
        rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf-8");

        JsonObject resultData = new JsonObject();
        try {
            Number count = Db.use().queryNumber("SELECT COUNT(*) FROM file_info WHERE date(create_time) = date(current_timestamp, 'localtime') OR date(update_time) = date(current_timestamp, 'localtime')");
            resultData.put("total", count);
            resultData.put("today", DateUtil.today());
            rc.end(resultData.toBuffer());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
